package com.lh0811.forge.pserv.basic.server.adapter.controller;

import com.github.pagehelper.PageInfo;
import com.lh0811.forge.dependency.basic_web.constant.AuthConstant;
import com.lh0811.forge.dependency.basic_web.response.ServerResponse;
import com.lh0811.forge.pserv.basic.api.param.CommBizNoCreateParam;
import com.lh0811.forge.pserv.basic.api.param.CommBizNoUpdateParam;
import com.lh0811.forge.pserv.basic.api.param.CommonBizNoQueryListParam;
import com.lh0811.forge.pserv.basic.api.param.CommonBizNoQueryPageParam;
import com.lh0811.forge.pserv.basic.api.vo.CommBizNoVo;
import com.lh0811.forge.pserv.basic.server.service.BizNoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import lombok.extern.slf4j.Slf4j;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@Tag(name = "基础服务-业务编号管理")
@RestController
@RequestMapping("/forge/plate/v1/basic/biz_no")
public class BizNoController {

    @Resource
    private BizNoService bizNoService;

    /**
     * 查询业务编号列表(分页)
     */
    @GetMapping("/query/page")
    @Operation(summary = "查询业务编号列表(分页)", parameters = {
            @Parameter(in = ParameterIn.HEADER, name = AuthConstant.TokenKey, description = "用户Token")
    })
    public ServerResponse<PageInfo<CommBizNoVo>> queryBizNoPageList(@ParameterObject @Valid CommonBizNoQueryPageParam param) throws Exception {
        return ServerResponse.createBySuccess("查询成功", bizNoService.queryBizNoPageList(param));
    }

    /**
     * 查询业务编号列表
     */
    @GetMapping("/query/list")
    @Operation(summary = "查询业务编号列表", parameters = {
            @Parameter(in = ParameterIn.HEADER, name = AuthConstant.TokenKey, description = "用户Token")
    })
    public ServerResponse<List<CommBizNoVo>> queryBizNoList(@ParameterObject @Valid CommonBizNoQueryListParam param) throws Exception {
        return ServerResponse.createBySuccess("查询成功", bizNoService.queryBizNoList(param));
    }

    /**
     * 创建业务编号记录
     */
    @PutMapping("/create")
    @Operation(summary = "创建业务编号记录", parameters = {
            @Parameter(in = ParameterIn.HEADER, name = AuthConstant.TokenKey, description = "用户Token")
    })
    public ServerResponse createBizNo(@Valid CommBizNoCreateParam param) throws Exception {
        bizNoService.createBizNo(param);
        return ServerResponse.createBySuccess();
    }


    /**
     * 修改业务编号记录
     */
    @PostMapping("/update")
    @Operation(summary = "修改业务编号记录", parameters = {
            @Parameter(in = ParameterIn.HEADER, name = AuthConstant.TokenKey, description = "用户Token")
    })
    public ServerResponse editBizNo(@Valid CommBizNoUpdateParam param) throws Exception {
        bizNoService.editBizNo(param);
        return ServerResponse.createBySuccess();
    }


    /**
     * 删除业务编号记录
     */
    @DeleteMapping("/{bizNoId}")
    @Operation(summary = "删除业务编号记录", parameters = {
            @Parameter(in = ParameterIn.HEADER, name = AuthConstant.TokenKey, description = "用户Token")
    })
    public ServerResponse deleteBizNo(@PathVariable(value = "bizNoId") Long bizNoId) throws Exception {
        bizNoService.deleteBizNo(bizNoId);
        return ServerResponse.createBySuccess();
    }


}
